<? require("core/base.php"); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>uptime - system ranking</title>
<link href="files/main.css" rel="stylesheet" type="text/css">
</head>

<body>
<table width="800" border="0" cellspacing="0" cellpadding="0">
  <tr> 
    <td><a href="index.php"><img src="img/hdr.png" alt="uptime" width="800" height="100" hspace="0" vspace="0" border="0"></a></td>
  </tr>  
  <tr>  
    <td valign="top" class="fons33"><?optionBar();?></td>
  </tr>
  <tr>  
    <td valign="top" class="fons33b">
      <table width="100%" border="0" cellspacing="0" cellpadding="8">
        <tr>
          <td><p><br>
              <span class="destacat"><br>
              <br>
              System ranking</span></p>
            <p><br>By OS (general)</p>
			  
            <table width="550" border="0" cellspacing="1" cellpadding="1">
              <tr> 
                <td width="39" class="hdrtaula">Pos</td>
                <td width="128" class="hdrtaula">OS</td>
                <td width="209" class="hdrtaula">Current confirmed Uptime</td>
                <td width="161" class="hdrtaula">Avg</td>
              </tr>
			  
<?
	$bd=new bd;
	
	$sQuery="SELECT s.os, SUM(u.uptime) AS uptime, (SELECT AVG(u3.uptime) as avguptime FROM uptime u3, subversions s2, configurations c2 WHERE c2.username=u3.username AND c2.machine=u3.machine AND c2.subversion=s2.subversion AND ((c2.fin_date IS NOT NULL AND u3.reg_date BETWEEN c2.ini_date AND c2.fin_date) OR (c2.fin_date IS NULL AND u3.reg_date>=c2.ini_date)) AND s2.os=s.os GROUP BY (s2.os)) AS avguptime FROM uptime u, subversions s, configurations c WHERE NOT EXISTS(SELECT reg_date FROM uptime u2 WHERE u2.username=u.username AND u2.machine=u.machine AND u2.reg_date>u.reg_date) AND c.username=u.username AND c.machine=u.machine AND c.fin_date IS NULL AND c.subversion=s.subversion GROUP BY s.os ORDER BY uptime DESC;";
	$bd->query($sQuery);
	
	if ($bd->getErrDescr()!="Ok")
		echo("<TR><TD colspan=\"7\">Database ".$bd->getErrDescr()."</TD></TR>");
	else
	{
		$r=$bd->getResultatObj();
		if (count($r)>0)
		{
			$i=1;
			foreach ($r as $k => $v)
			{
				echo("<TR>");
				echo("<TD class=\"celltaulafirst\">".$i."</TD>");
				echo("<TD class=\"celltaula\">".$v->os."</TD>");
				echo("<TD class=\"celltaula\">".niceUptime($v->uptime)."</TD>");
				echo("<TD class=\"celltaula\">".niceUptime(round($v->avguptime))."</TD>");
				echo("</TR>");
				
				$i++;
			}
		}
	}

?>			  
            </table>
            <p> <br>
              <br>
              <br>
              By OS and version</p>
			  
            <table width="550" border="0" cellspacing="1" cellpadding="1">
              <tr> 
                <td width="39" class="hdrtaula">Pos</td>
                <td width="128" class="hdrtaula">OS and version</td>
                <td width="209" class="hdrtaula">Current confirmed Uptime</td>
                <td width="161" class="hdrtaula">Avg</td>
              </tr>
			  
<?
	$bd=new bd;
	
	$sQuery="SELECT s.os, s.version, SUM(u.uptime) AS uptime, (SELECT AVG(u3.uptime) as avguptime FROM uptime u3, subversions s2, configurations c2 WHERE c2.username=u3.username AND c2.machine=u3.machine AND c2.subversion=s2.subversion AND ((c2.fin_date IS NOT NULL AND u3.reg_date BETWEEN c2.ini_date AND c2.fin_date) OR (c2.fin_date IS NULL AND u3.reg_date>=c2.ini_date)) AND s2.os=s.os AND s2.version=s.version GROUP BY s2.os, s2.version) AS avguptime FROM uptime u, subversions s, configurations c WHERE NOT EXISTS(SELECT reg_date FROM uptime u2 WHERE u2.username=u.username AND u2.machine=u.machine AND u2.reg_date>u.reg_date) AND c.username=u.username AND c.machine=u.machine AND c.fin_date IS NULL AND c.subversion=s.subversion GROUP BY s.os, s.version ORDER BY uptime DESC;
";
	$bd->query($sQuery);
	
	if ($bd->getErrDescr()!="Ok")
		echo("<TR><TD colspan=\"7\">Database ".$bd->getErrDescr()."</TD></TR>");
	else
	{
		$r=$bd->getResultatObj();
		if (count($r)>0)
		{
			$i=1;
			foreach ($r as $k => $v)
			{
				echo("<TR>");
				echo("<TD class=\"celltaulafirst\">".$i."</TD>");
				echo("<TD class=\"celltaula\">".$v->os." ".$v->version."</TD>");
				echo("<TD class=\"celltaula\">".niceUptime($v->uptime)."</TD>");
				echo("<TD class=\"celltaula\">".niceUptime(round($v->avguptime))."</TD>");
				echo("</TR>");
				
				$i++;
			}
		}
	}

?>			  
            </table>
            <p>			

            <p> <br>
              <br>
              <br>
              By CPU type</p>
			  
            <table width="550" border="0" cellspacing="1" cellpadding="1">
              <tr> 
                <td width="39" class="hdrtaula">Pos</td>
                <td width="128" class="hdrtaula">CPU</td>
                <td width="209" class="hdrtaula">Current confirmed Uptime</td>
                <td width="161" class="hdrtaula">Avg</td>
              </tr>
			  
<?
	$bd=new bd;
	
	$sQuery="SELECT c.cpu, SUM(u.uptime) AS uptime, (SELECT AVG(u3.uptime) as avguptime FROM uptime u3, configurations c2 WHERE c2.username=u3.username AND c2.machine=u3.machine AND ((c2.fin_date IS NOT NULL AND u3.reg_date BETWEEN c2.ini_date AND c2.fin_date) OR (c2.fin_date IS NULL AND u3.reg_date>=c2.ini_date)) AND c2.cpu=c.cpu GROUP BY c2.cpu) AS avguptime FROM uptime u, configurations c WHERE NOT EXISTS(SELECT reg_date FROM uptime u2 WHERE u2.username=u.username AND u2.machine=u.machine AND u2.reg_date>u.reg_date) AND c.username=u.username AND c.machine=u.machine AND c.fin_date IS NULL GROUP BY c.cpu ORDER BY uptime DESC;";
	$bd->query($sQuery);
	
	if ($bd->getErrDescr()!="Ok")
		echo("<TR><TD colspan=\"7\">Database ".$bd->getErrDescr()."</TD></TR>");
	else
	{
		$r=$bd->getResultatObj();
		if (count($r)>0)
		{
			$i=1;
			foreach ($r as $k => $v)
			{
				echo("<TR>");
				echo("<TD class=\"celltaulafirst\">".$i."</TD>");
				echo("<TD class=\"celltaula\">".$v->cpu."</TD>");
				echo("<TD class=\"celltaula\">".niceUptime($v->uptime)."</TD>");
				echo("<TD class=\"celltaula\">".niceUptime(round($v->avguptime))."</TD>");
				echo("</TR>");
				
				$i++;
			}
		}
	}

?>			  
            </table>
			
			<br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
              <br>
            </p>
	<DIV align="right">
      <a href="http://validator.w3.org/check?uri=referer"><img border="0"
          src="http://www.w3.org/Icons/valid-html401"
          alt="Valid HTML 4.01!" height="31" width="88"></a>
    </DIV>			
            <p>&nbsp;</p></td>
        </tr>
      </table>
      
    </td>
  </tr>
</table>
</body>
</html>
